<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/22/022
 * Time: 9:33
 */

namespace app\Lib\Model\Push;


use app\Lib\Exception\BlException;

class WeiXinPushRecording
{
    private $open_id;
    private $template_id;
    private $push_data;
    private $status;
    private $error_message;

    /**
     * @param mixed $open_id
     */
    public function setOpenId($open_id)
    {
        $this->open_id = $open_id;
    }

    /**
     * @param mixed $template_id
     */
    public function setTemplateId($template_id)
    {
        $this->template_id = $template_id;
    }

    /**
     * @param mixed $push_data
     */
    public function setPushData($push_data)
    {
        $this->push_data = $push_data;
    }

    /**
     * @param mixed $status
     */
    public function setStatus($status = 1)
    {
        $this->status = $status;
    }

    /**
     * @param mixed $error_message
     */
    public function setErrorMessage($error_message)
    {
        $this->error_message = $error_message;
    }


    /**
     * @return bool
     * @throws BlException
     */
    public function run(){
        $table = new \app\Lib\Model\DbModel\WeixinPushRecording();
        $data = [
            $table->_status=>$this->status,
            $table->_open_id=>$this->open_id,
            $table->_template_id=>$this->template_id,
            $table->_error_message=>$this->error_message,
            $table->_push_data=>$this->push_data,
            $table->_push_time=>time(),
        ];
//        dump($data);
        $result  = $table->insert($data);
        if(!$result){
            throw new BlException('记录推送失败');
        }
        return true;
    }
}